# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=imgviz
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.2.2
pkgrel=1
pkgdesc='Image Visualization Tools (object detection, semantic and instance segmentation) (mingw-w64)'
arch=('any')
url="https://github.com/wkentaro/imgviz"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-pillow" "${MINGW_PACKAGE_PREFIX}-python-numpy" "${MINGW_PACKAGE_PREFIX}-python-matplotlib" "${MINGW_PACKAGE_PREFIX}-python-yaml")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
makedepends=("unzip" "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("$_realname-${pkgver}.zip::https://github.com/wkentaro/imgviz/archive/v${pkgver}.zip")
noextract=("$_realname-${pkgver}.zip")
sha256sums=('4ccdee6af44d9b259e0062f53b755da17cd801a946c25b656d11f49da0c5a672')

prepare() {  
  cd "$srcdir"
  unzip "$_realname-${pkgver}.zip"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  PYTHONPATH="${PWD}/build/lib" ${MINGW_PREFIX}/bin/pytest -v || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
